const pkg = require('./package.json')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const ENV = process.env.NODE_ENV || 'development'
const HOST = 'http://39.98.21.66:8989'

process.env.VUE_APP_NAME = process.env.VUE_APP_NAME || pkg.appName

module.exports = {
  configureWebpack: config => {
    if (ENV === 'production') {
      config.plugins.push(new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: /\.(js|css|html)$/,
        threshold: 10240,
        minRatio: 0.8
      }))
      config.externals = {
        'vue': 'Vue',
        'vue-router': 'VueRouter',
        'axios': 'axios'
      }
    }
  },
  productionSourceMap: false,
  devServer: {
    open: false,
    hotOnly: false,
    proxy: {
      '/api': {
        target: HOST,
        changeOrigin: true
      }
    }
  }
}
